package com.bawei.view_animator;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * 动画：
 * 1。帧动画
 * 2。视图动画(Animation)：动画结束恢复初始状态
 * 3。属性动画(Animator)：动画结束保持最后状态
 * （1）透明度
 * （2）旋转
 * （3）平移
 * （4）缩放
 * 4.差值器：八大差值器
 *  LinearInterpolator：匀速
 *  AccelerateInterpolator :加速
 *  DecelerateInterpolator ：减速
 *  AccelerateDecelerateInterpolator ：先加速后减速
 *  BounceInterpolator ：弹球效果
 *  CycleInterpolator ：周期效果，视频点赞用到
 *  AnticipateInterpolator ：先退后再加速前进
 *  OvershootInterpolator ：超出终点后回到结束样式
 *  AnticipateOvershootInterpolator ： 先退后再加速前进，超出终点后回到结束样式
 * 5.估值器
 *
 * 6。差值器和估值器区别：
 * 差值器：变化规律
 * 估值器：变化值 fraction 0-1   贝塞尔曲线点赞效果
 *
 */
public class MainActivity extends AppCompatActivity {
    private ImageView iv;
    private MyView myView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.iv);
        myView = (MyView) findViewById(R.id.my_view);
        myView.start(new MyView.FinishListener() {
            @Override
            public void onFinish() {
                Toast.makeText(MainActivity.this, "倒计时结束", Toast.LENGTH_SHORT).show();
            }
        });
    }
    //属性动画：组合  "Alpha"  "TranslationX"  "TranslationY"   "Rotation"  "ScaleX" "ScaleY"
    public void animator(View view) {
        ObjectAnimator alpha = ObjectAnimator.ofFloat(iv, "Alpha", 1, 0, 1, 0, 1);
        ObjectAnimator translationX = ObjectAnimator.ofFloat(iv, "TranslationX", 0, 300, 100);
        ObjectAnimator translationY = ObjectAnimator.ofFloat(iv, "TranslationY", 0, 300, 100);
        ObjectAnimator rotation = ObjectAnimator.ofFloat(iv, "Rotation", 0, 360, 90);
        ObjectAnimator ScaleX = ObjectAnimator.ofFloat(iv, "ScaleX", 1,2,3,1.5f,1);
        ObjectAnimator ScaleY = ObjectAnimator.ofFloat(iv, "ScaleY", 1,2,3,1.5f,1);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(alpha,translationX,translationY,rotation,ScaleX,ScaleY);
        animatorSet.setDuration(5000);
        animatorSet.start();
    }
    //视图动画
    public void animation(View view) {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.set);
        iv.startAnimation(animation);
    }
}